package com.game.chinesechess.piece.specific;


import com.game.chinesechess.piece.chess;
import com.game.chinesechess.util.Point;

public class soldierChess extends chess {
    public soldierChess(Color color, int x, int y) {
        this.color = color;
        this.point = new Point(x, y);
    }

    @Override
    public Boolean check(chess[][] map, int toX, int toY) {
        int xDistance = this.point.x - toX;
        int YDistance = Math.abs(this.point.y - toY);
        if (this.color == Color.RED)
            if (this.point.x > 4)
                return xDistance == 1 && YDistance == 0;
            else
                return (xDistance == 1 && YDistance == 0) || (xDistance == 0 && YDistance == 1);
        else {
            if (this.point.x < 4)
                return (xDistance == -1 && YDistance == 0);
            else
                return (xDistance == -1 && YDistance == 0) || (xDistance == 0 && YDistance == 1);
        }
    }

    @Override
    public String getName() {
        return this.color == Color.RED ? "兵" : "卒";
    }
}
